Skip to content

feat(enhanced): add include/exclude filtering support for shared modules #3904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 48 commits into
base: main
Choose a base branch
from

Conversation

ScriptedAlchemy
Copy link
Member

Summary

Implements basic share filtering functionality for ConsumeSharedPlugin and ProvideSharedPlugin, allowing fine-grained control over which shared modules are consumed or provided based on version requirements and request patterns.

Part of incremental PR plan - Step 4: Basic Share Filtering

Features Added

  • Version Filtering: Include/exclude shared modules based on semver version requirements
  • Request Filtering: Include/exclude shared modules based on request patterns (string/RegExp)
  • Singleton Warnings: Automatic warnings when filtering singleton modules
  • Comprehensive Testing: Unit tests and config test cases for all filtering scenarios

Technical Implementation

  • Enhanced ConsumeSharedPlugin with version and request filtering logic
  • Enhanced ProvideSharedPlugin with version and request filtering logic
  • Added testRequestFilters utility for request pattern matching
  • Added addSingletonFilterWarning utility for singleton filter warnings
  • Updated JSON schemas and TypeScript declarations
  • Generated new schema validation files

Test Plan

  • Unit tests for filtering utilities (11 test cases)
  • Config test cases for consume filtering scenarios
  • Config test cases for provide filtering scenarios
  • All existing sharing tests continue to pass
  • Schema generation successful

🤖 Generated with Claude Code

ScriptedAlchemy and others added 3 commits July 11, 2025 23:39
- Separate handling for container, federation, and remote dependencies
- Improved support for runtimeChunk: 'single' configuration
- Proper remote module hoisting using the new addRemoteDependency hook
- Simplified cleanup logic for better performance
- Changed runtime chunk detection to include all chunks with runtime
- Added comprehensive unit tests
- Add testRequestFilters and addSingletonFilterWarning utilities
- Update ConsumeSharedPlugin with version and request filtering
- Update ProvideSharedPlugin with version and request filtering
- Update schemas to include include/exclude filter properties
- Add comprehensive unit tests for filtering functionality
- Add config test cases for consume and provide filtering

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link

changeset-bot bot commented Jul 12, 2025

🦋 Changeset detected

Latest commit: 5c7eabc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 33 packages
Name Type
@module-federation/enhanced Major
@module-federation/modern-js Major
@module-federation/nextjs-mf Patch
@module-federation/node Patch
@module-federation/rsbuild-plugin Major
@module-federation/rspress-plugin Major
@module-federation/storybook-addon Major
@module-federation/modernjsapp Patch
remote5 Patch
website-new Patch
@module-federation/runtime Major
@module-federation/rspack Major
@module-federation/webpack-bundler-runtime Major
@module-federation/sdk Major
@module-federation/runtime-tools Major
@module-federation/managers Major
@module-federation/manifest Major
@module-federation/dts-plugin Major
@module-federation/third-party-dts-extractor Major
@module-federation/devtools Major
@module-federation/bridge-react Major
@module-federation/bridge-vue3 Major
@module-federation/bridge-shared Major
@module-federation/bridge-react-webpack-plugin Major
@module-federation/retry-plugin Major
@module-federation/data-prefetch Major
@module-federation/error-codes Major
@module-federation/inject-external-runtime-core-plugin Major
@module-federation/runtime-core Major
create-module-federation Major
@module-federation/cli Major
@module-federation/esbuild Patch
@module-federation/utilities Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

netlify bot commented Jul 12, 2025

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit 5c7eabc
🔍 Latest deploy log https://app.netlify.com/projects/module-federation-docs/deploys/687aebf83872b400082f400e
😎 Deploy Preview https://deploy-preview-3904--module-federation-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

ScriptedAlchemy and others added 8 commits July 12, 2025 16:50
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Fixes TypeScript error TS2742 where inferred type could not be named
without portable React types reference.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Fixed main entry path in project.json to correct location
- Added extends to tsconfig.json to inherit base configuration
- Added dependsOn configuration for proper build dependencies

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- add include/exclude properties to share plugin schema
- update share plugin to pass through include/exclude filters to underlying plugins
- generate updated typescript definitions and validation schemas
- support version and request filtering for both include and exclude
- part of pr4: basic share filtering - include/exclude by version
…ugin and ConsumeSharedPlugin

- Add include/exclude version filtering support to ProvideSharedPlugin
- Add include/exclude version filtering support to ConsumeSharedPlugin
- Implement proper filtering logic that prevents filtered modules from being shared
- Add type definitions for IncludeExcludeOptions interface
- Update provide-filters integration test with proper share scope initialization
- Fix unit test mock compilation to extend actual Compilation class
- All tests passing (7/7 provide-filters tests, 13/13 unit tests)

This implements PR4 (Basic Share Filtering - Include/Exclude by Version) requirements
by allowing filtering of shared modules based on semantic version ranges.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…hare-filter branch

This directory was accidentally created during development but doesn't exist
in the original share-filter branch and was causing compilation errors.

The provide-filters test is working correctly and all filtering functionality
is properly implemented for PR4 (Basic Share Filtering).
@ScriptedAlchemy ScriptedAlchemy force-pushed the feat/basic-share-filtering branch from 60e2ad7 to 9bab6fb Compare July 15, 2025 01:10
@ScriptedAlchemy ScriptedAlchemy changed the base branch from main to feat/enhanced-hoist-container-refs July 15, 2025 21:43
ScriptedAlchemy and others added 12 commits July 15, 2025 14:46
- Add browser caching for Playwright and Cypress
- Add explicit Cypress installation step
- Add PLAYWRIGHT_CACHE_HIT environment variable
- Add warm Nx cache step
- Use --parallel=4 for faster builds
- Align with build-and-test workflow strategy

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add addRemoteDependency hook calls in RemoteModule.ts build method
- Ensures HoistContainerReferencesPlugin can properly track remote dependencies
- Calls hook for both RemoteToExternalDependency and FallbackDependency
- Brings current branch in sync with share-filter branch hook implementations

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Update tsconfig.json to use TypeScript project references structure
- Create missing tsconfig.lib.json and tsconfig.spec.json files
- Update project.json to use tsconfig.lib.json and add external dependencies
- Fix missing return statement in isStoryBook function
- Fix NODE_ENV access to use bracket notation for strict mode
- Brings rsbuild-plugin build configuration in line with other rollup packages

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
The main entry was pointing to the wrong path (packages/rsbuild-plugin/cli/src/index.ts)
when it should be packages/rsbuild-plugin/src/cli/index.ts. This was causing TypeScript
compilation errors during the build process.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…nfig

Similar to how SDK and other packages handle it, explicitly set the external
array in rollup config to ensure proper handling of workspace dependencies
during TypeScript compilation.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add missing "types" field to package.json (like rspack and sdk have)
- Add "noImplicitAny": false to tsconfig.json to match rspack's config
- This should help TypeScript resolve workspace dependencies correctly

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Use path.resolve with process.cwd() to create absolute paths for the
input files, matching how other packages like rspack handle their
rollup configuration.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Match the path format used by other packages like data-prefetch
which use 'packages/package-name/src/...' relative paths.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…lution

The root cause was manually overriding rollupConfig.external which broke
nx's automatic workspace dependency resolution mechanism. By removing this
override and letting nx handle externals via project.json, TypeScript can
now properly resolve workspace dependencies during the rollup build.

This aligns rsbuild-plugin with working packages like cli and data-prefetch
that don't manually override external configuration.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Remove dep-graph.json and deps.json files that were accidentally
committed during the investigation process.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
ScriptedAlchemy and others added 21 commits July 15, 2025 17:04
Add explicit TypeScript path mappings in tsconfig.json to help
the TypeScript compiler resolve workspace dependencies during
CI builds. This should resolve the module resolution issues
in stricter CI environments.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Build SDK with skip cache first to ensure workspace dependencies are available
- Then build all packages with normal caching to resolve TypeScript module resolution issues
- This ensures workspace packages are properly built and available for dependent packages

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Update the RemoteModule test build describe block to properly mock
the FederationModulesPlugin.getCompilationHooks method to match
the implementation on share-filter branch. This resolves the TypeError
about compilation argument validation.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add comment to force CI to rebuild modernjs package which was missing files.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Ensure proper cleanup of module mocks between test runs to prevent
compilation instance validation errors.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Replace instance-level mocking with module-level mocking to avoid
webpack Compilation instance validation errors.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Fix the mock to directly export the plugin instead of wrapping it in
a default property, matching the actual default import pattern.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Trigger another build attempt to resolve missing dist files in CI.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Reduce parallel build workers in devtools workflow to prevent
race conditions and improve build reliability.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Allow the warm cache step to use cache for better performance
while keeping skip cache only for the main build step.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Accept utilities and webpack dependencies in app package.json files
- Use tsconfig.lib.json for rsbuild-plugin project
- Accept incoming pnpm-lock.yaml changes

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add import caching to SDK importNodeModule to prevent circular calls
- Add import caching to node runtime plugin importNodeModule
- Add ESM module caching to prevent loadModule recursion
- Use direct dynamic import in vm.Script fallback to avoid cycles
- Add regression test for maximum call stack exceeded scenario

Fixes RangeError: Maximum call stack size exceeded when NextJS apps
use Module Federation with both SDK and node runtime plugin importing
each other's modules through importModuleDynamically callbacks.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Now that import caching prevents infinite recursion, we can use the
proper importNodeModule function instead of the workaround in
vm.Script importModuleDynamically fallback.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…dule directly

Remove vm.constants?.USE_MAIN_CONTEXT_DEFAULT_LOADER fallback since caching prevents recursion.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…OADER

Prefer using vm.constants.USE_MAIN_CONTEXT_DEFAULT_LOADER when available,
fallback to cached importNodeModule to prevent recursion.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Export the cache and clear it in beforeEach to ensure test isolation.
The caching mechanism was causing tests to reuse cached promises from
previous tests instead of running the intended mocked behavior.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Use direct export declaration instead of separate export statement
to match the pattern used by all other exports in the file.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Resolved conflict in .github/workflows/build-and-test.yml (kept main version)
- Resolved conflict in packages/rsbuild-plugin/project.json
  (kept both main changes and dependsOn config)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@ScriptedAlchemy ScriptedAlchemy force-pushed the feat/enhanced-hoist-container-refs branch from 6ae92a4 to 787ba92 Compare July 17, 2025 22:55
Base automatically changed from feat/enhanced-hoist-container-refs to main July 18, 2025 03:45
ScriptedAlchemy and others added 2 commits July 18, 2025 16:58
- Remove unnecessary wrapper functions in ConsumeSharedPlugin and ProvideSharedPlugin
- Use createLookupKeyForSharing utility function directly
- Remove singleton warnings for request include/exclude filters
- Keep singleton warnings only for version include/exclude filters
- Sync devtools.yml with main branch

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant